<template>
  <!-- 监控事件配置审核明细-->
  <el-dialog
    :title="title"
    center
    :visible.sync="openState"
    width="1024px"
    :close-on-click-modal="false"
    :before-close="handleClose"
  >
    <el-form ref="form" :model="form" :rules="rules" :disabled="true" label-width="110px">
      <!--监控事件配置审核明细-->

      <el-row>
        <el-col :span="12">
          <el-form-item label="事件名称" prop="eventNm">
            <el-input v-model="form.eventNm" placeholder="事件名称" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="业务类型" prop="bussType">
            <el-input v-model="form.bussType" placeholder="业务类型" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="监控类型" prop="monitorType">
            <el-select v-model="form.monitorType" placeholder="监控类型" style="width: 100%">
              <el-option
                v-for="dict in dictMap.MONITOR_TYPE"
                :key="dict.value"
                :label="dict.text"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
<!--        <el-col :span="12">-->
<!--          <el-form-item label="监控周期" prop="monitorCycle">-->
<!--            <el-select v-model="form.monitorCycle" placeholder="监控周期" style="width: 100%">-->
<!--              <el-option-->
<!--                v-for="dict in dictMap.MONITOR_CYCLE"-->
<!--                :key="dict.value"-->
<!--                :label="dict.text"-->
<!--                :value="dict.value"-->
<!--              ></el-option>-->
<!--            </el-select>-->
<!--          </el-form-item>-->
<!--        </el-col>-->
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="超时时间" prop="timeoutLimit" v-if="timeoutLimitShow">
            <el-input v-model="form.timeoutLimit" placeholder="超时时间" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="24">
          <el-form-item label="执行SQL" prop="executeSql">
            <el-input v-model="form.executeSql" placeholder="执行SQL" type="textarea" autosize />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="approve" v-show="approveShow">审 核</el-button>
      <el-button type="primary" @click="reject" v-show="rejectShow">拒 绝</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { monitorConfApproveDetail, monitorConfApprove, monitorConfReject } from "@/api/cnaps/bizMng/monitorConf.js";
import { listPageMixin } from "@/libs/listPageMixin";

export default {
  name: "monitorConfApproveDialog",
  mixins: [listPageMixin],
  components: {},
  data() {
    return {
      title: "",
      // 是否显示弹出层
      openState: false,
      rejectShow: false,
      approveShow: false,
      timeoutLimitShow: false,
      // 字段可编辑控制

      //数据字典
      searchFormDictList: ["MONITOR_TYPE", "MONITOR_CYCLE"],
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      opButtonList: () => {
        return [];
      },
    };
  },
  mounted() {},
  methods: {
    // 表单重置
    reset() {
      this.resetForm("form");
      this.$set(this, "form", {});
    },
    // 关闭回掉
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          this.reset();
          done();
        })
        .catch((_) => {});
    },
    show(row) {
      this.form = row;
      this.title = "监控事件配置审核明细";
      this.openState = true;

      this.monitorTypeChange();
      this.monitorConfApproveDetail(row);

      if (row.checkStatus == "00" || row.checkStatus == "01" || row.checkStatus == "02") {
        this.approveShow = true;
        this.rejectShow = true;
      } else {
        this.approveShow = false;
        this.rejectShow = false;
      }
    },

    monitorConfApproveDetail: function (row) {
      monitorConfApproveDetail(row).then((response) => {
        this.showData(response);
      });
    },
    showData: function (response) {
      this.form = response.result.data;
    },

    /** TODO审批按钮 */
    approve() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          monitorConfApprove(this.form).then((res) => {
            if (res.code === "S") {
              this.msgSuccess("审批通过");
              this.cancel();
            }
          });
        }
      });
    },

    /** TODO拒绝按钮 */
    reject() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          monitorConfReject(this.form).then((res) => {
            if (res.code === "S") {
              this.msgSuccess("审批已拒绝");
              this.cancel();
            }
          });
        }
      });
    },

    cancel() {
      this.openState = false;
      this.reset();
      this.$emit("editComplete", true);
    },

    monitorTypeChange() {
      let monitorType = this.form.monitorType;
      if (monitorType == "02") {
        //超时

        this.timeoutLimitShow = true;
        this.rules.timeoutLimit = {
          required: true,
          message: "请输入超时时间",
          trigger: "blur",
        };
      } else {
        //发送失败或记账失败
        this.$set(this.form, "timeoutLimit", "");
        this.timeoutLimitShow = false;
        this.rules.timeoutLimit = {
          required: false,
          message: "请输入超时时间",
          trigger: "blur",
        };
      }
    },
  },
};
</script>
<style>
.label-header-msg {
  font-weight: bold;
}

.form-card {
  margin-bottom: 10px;
}
</style>
